//% color="#9F32F1" iconWidth=50 iconHeight=40
namespace RFID {

    //% block="Initialize RFID/NFC module interface I2C address 0X24" blockType="command" 
    export function DFRobot_PN532_IIC(parameter: any, block: any) {
        Generator.addInclude("DFRobot_NFC0231", "#include <DFRobot_NFC0231_K10.h>");
        Generator.addObject(`DFRobot_PN532_IIC`, `DFRobot_PN532_IIC`, `pn532;`);
        Generator.addCode(`pn532.begin();`);
    }

    //% block="RFID/NFC module Data block [data_block_w] one [data_block_num] byte written to [data_w]" blockType="command"    
    //% data_block_w.shadow="dropdown" data_block_w.options=W1
    //% data_block_num.shadow="dropdown" data_block_num.options=N1
    //% data_w.shadow="number" data_w.defl=200
    export function writeData(parameter: any, block: any) {
        let data_block_w = parameter.data_block_w.code;
        let data_block_num = parameter.data_block_num.code;
        let data_w = parameter.data_w.code;
        Generator.addCode(`pn532.writeData(${data_block_w}, ${data_block_num}, ${data_w});`);
    } 

    //% block="Read all data from RFID/NFC module Data block [data_block] (string)" blockType="reporter"    
    //% data_block.shadow="dropdown" data_block.options=D1 
    export function readData1(parameter: any, block: any) {
        let data_block = parameter.data_block.code;
        Generator.addCode(`pn532.readData(${data_block})`);
    }

    //% block="Read RFID/NFC module Data block [data_block_r] byte data [data_block_num_r] (number)" blockType="reporter"    
    //% data_block_r.shadow="dropdown" data_block_r.options=R2
    //% data_block_num_r.shadow="dropdown" data_block_num_r.options=R3
    export function readData2(parameter: any, block: any) {
        let data_block_r = parameter.data_block_r.code;
        let data_block_num_r = parameter.data_block_num_r.code;
        Generator.addCode(`pn532.readData(${data_block_r}, ${data_block_num_r})`);
    } 

    //% block="Read RFID/NFC module UID(string)" blockType="reporter"    
    export function readUid(parameter: any, block: any) {
        Generator.addCode(`pn532.readUid()`);
    } 
}

